﻿using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Primitives;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ifile
{
    public class Sample01
    {
        //: IFileProvider
        ////构建一个层次化的目录结构（抽象的概念）
        //public IDirectoryContents GetDirectoryContents(string subpath)
        //{
        //    throw new NotImplementedException();
        //}

        //public IFileInfo GetFileInfo(string subpath)
        //{
        //    throw new NotImplementedException();
        //}

        //public IChangeToken Watch(string filter)
        //{
        //    throw new NotImplementedException();
        //}
        public static void Run()
        {
            var provider = new ServiceCollection().AddSingleton<IFileProvider>();
        }

        
    }
    public class FileManager
    {
        private readonly IFileProvider _fileProvider;

        public FileManager(IFileProvider fileProvider)
        {
            _fileProvider = fileProvider;
        }
        public void Dir()
        {
            var indent = -1;
            void Get(string subpath)
            {
                indent++;
                foreach (var fileinfo in _fileProvider.GetDirectoryContents(subpath))
                {
                    Console.WriteLine(new string('\t', indent) + fileinfo.Name);
                    if (fileinfo.IsDirectory)
                    {
                        Get($@"{subpath}\{fileinfo.Name}");
                    }
                }
            }
            Get("");
        
        }

    }
}
